package demo2;

import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 19182
 * Date: 2025-07-15
 * Time: 21:34
 */
public class ScoreCompare implements Comparator<Student> {
    @Override
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }

    public static void main2(String[] args) {
        Student student1 = new Student("张三", 10);
        Student student2 = new Student("李四", 20);
        Student student3 = new Student("王五", 30);
        Student[] students = new Student[3];
        students[0] = student1;
        students[1] = student2;
        students[2] = student3;
        ScoreCompare scoreCompare = new ScoreCompare();
        Arrays.sort(students, scoreCompare);
        System.out.println(Arrays.toString(students));
    }
}
